package models

type User struct {
	ID int `gorm:"primary_key;AUTO_INCREMENT;cloumn:id;type:int(11) unsigned;not null" form:"id" json:"id"`
	Name string `gorm:"cloumn:name;type:varchar(30)" form:"name" json:"name"`
	Password string `gorm:"cloumn:password;type:varchar(64);not null" form:"password" json:"password"`
	Sex int `gorm:"cloumn:sex;type:tinyint(2) unsigned; default: 0" form:"sex" json:"sex"`
	CreatedAt int64	`gorm:"column:created_at;type:int(11) unsigned" json:"created_at"`
	UpdatedAt int64	`gorm:"column:updated_at;type:int(11) unsigned" json:"updated_at"`
	Avatar string `gorm:"column:avatar;type:varchar(255)" json:"avatar"`
	
	Groups []UserGroup `gorm:"ForeignKey:UserID;AssociationForeignKey:ID" json:"groups"`  // 用户创建群
	UserGroupS []UserGroup `gorm:"many2many:user_group_relations;ForeignKey:ID;AssociationForeignKey:ID" json:"user_group_s"` // 用户所属群
}

// 设置表名
func (u *User) TableName() string {
	return "user"
}

